package com.wanjia.estate.controller;



import com.wanjia.estate.exception.ControllerException;
import com.wanjia.estate.exception.JmhxxSearchException;
import com.wanjia.estate.exception.PaperDoorException;
import com.wanjia.estate.exception.TaoCiDataException;
import com.wanjia.estate.pojo.model.JsonResult;
import org.springframework.web.bind.annotation.ExceptionHandler;


public class BaseController {
    /*操作成功的状态码*/
    public static final int OK = 200;

    @ExceptionHandler(value = ControllerException.class)//用于统一处理抛出的异常
    public JsonResult<Object> handleException(Throwable e) {
        JsonResult<Object> result = new JsonResult<>(e);

        if (e instanceof PaperDoorException) {
            result.setCode(14001);
            result.setMessage("出纸口未关闭，请关闭！");
        }if (e instanceof TaoCiDataException) {
            result.setCode(14002);
            result.setMessage("查询套次信息比对失败");
        }if (e instanceof JmhxxSearchException) {
            result.setCode(14003);
            result.setMessage("居民户信息查询失败");
        }
        return result;
    }
}
